Writing a program in C++ and I need help [migrated]

Posted by compscinoob on Programmers See other posts from Programmers or by compscinoob
Published on 2012-06-06T03:51:40Z Indexed on 2012/06/06 4:47 UTC
Read the original article Hit count: 196

Filed under:
|
|

So I am a new to this. I am trying to write a program with a function

double_product(vector< double > a, vector< double > b) that computes the scalar product of two vectors. The scalar product is

$a_{0}b_{0}+a_{1}b_{1}+...a_{n-1}b_{n-1}$.

Here is what I have. It is a mess, but I am trying!

#include<iostream>

#include<vector>

using namespace std;

class Scalar_product
{

public:

    Scalar_product(vector<double> a, vector<bouble> b);

};


double scalar_product(vector<double> a, vector<double> b) 
{

   double product = 0;

   for (int i=0; i <=a.size()-1; i++)

       for (int i=0; i <=b.size()-1; i++)

           product = product + (a[i])*(b[i]);

   return product;

}

int main()
{

    cout << product << endl;

    return 0;

}

© Programmers or respective owner

Related posts about c++

Related posts about functions